home *** CD-ROM | disk | FTP | other *** search
/ Digital Background Bonanza / Digital Background Bonanza - Disc 1.iso / pc / DBB1.swf / scripts / __Packages / mx / controls / ComboBox.as < prev    next >
Encoding:
Text File  |  2007-03-09  |  15.2 KB  |  530 lines

  1. class mx.controls.ComboBox extends mx.controls.ComboBase
  2. {
  3.    var __labels;
  4.    var data;
  5.    var __dropdownWidth;
  6.    var __width;
  7.    var selectedIndex;
  8.    var __dropdown;
  9.    var dataProvider;
  10.    var __labelFunction;
  11.    var owner;
  12.    var mask;
  13.    var border_mc;
  14.    var text_mc;
  15.    var getValue;
  16.    var length;
  17.    var selectedItem;
  18.    var isPressed;
  19.    var __selectedIndexOnDropdown;
  20.    var __initialSelectedIndexOnDropdown;
  21.    var __dataProvider;
  22.    var selected;
  23.    var dispatchEvent;
  24.    static var symbolName = "ComboBox";
  25.    static var symbolOwner = mx.controls.ComboBox;
  26.    static var version = "2.0.2.126";
  27.    var clipParameters = {labels:1,data:1,editable:1,rowCount:1,dropdownWidth:1};
  28.    static var mergedClipParameters = mx.core.UIObject.mergeClipParameters(mx.controls.ComboBox.prototype.clipParameters,mx.controls.ComboBase.prototype.clipParameters);
  29.    var className = "ComboBox";
  30.    var _showingDropdown = false;
  31.    var __rowCount = 5;
  32.    var dropdownBorderStyle = undefined;
  33.    var initializing = true;
  34.    var __labelField = "label";
  35.    var bInKeyDown = false;
  36.    function ComboBox()
  37.    {
  38.       super();
  39.    }
  40.    function init()
  41.    {
  42.       super.init();
  43.    }
  44.    function createChildren()
  45.    {
  46.       super.createChildren();
  47.       this.editable = this.editable;
  48.       if(this.__labels.length > 0)
  49.       {
  50.          var _loc6_ = new Array();
  51.          var _loc3_ = 0;
  52.          while(_loc3_ < this.labels.length)
  53.          {
  54.             _loc6_.addItem({label:this.labels[_loc3_],data:this.data[_loc3_]});
  55.             _loc3_ = _loc3_ + 1;
  56.          }
  57.          this.setDataProvider(_loc6_);
  58.       }
  59.       this.dropdownWidth = typeof this.__dropdownWidth != "number" ? this.__width : this.__dropdownWidth;
  60.       if(!this._editable)
  61.       {
  62.          this.selectedIndex = 0;
  63.       }
  64.       this.initializing = false;
  65.    }
  66.    function onKillFocus(n)
  67.    {
  68.       if(this._showingDropdown && n != null)
  69.       {
  70.          this.displayDropdown(false);
  71.       }
  72.       super.onKillFocus();
  73.    }
  74.    function getDropdown()
  75.    {
  76.       if(this.initializing)
  77.       {
  78.          return undefined;
  79.       }
  80.       if(!this.hasDropdown())
  81.       {
  82.          var _loc3_ = new Object();
  83.          _loc3_.styleName = this;
  84.          if(this.dropdownBorderStyle != undefined)
  85.          {
  86.             _loc3_.borderStyle = this.dropdownBorderStyle;
  87.          }
  88.          _loc3_._visible = false;
  89.          this.__dropdown = mx.managers.PopUpManager.createPopUp(this,mx.controls.List,false,_loc3_,true);
  90.          this.__dropdown.scroller.mask.removeMovieClip();
  91.          if(this.dataProvider == undefined)
  92.          {
  93.             this.dataProvider = new Array();
  94.          }
  95.          this.__dropdown.setDataProvider(this.dataProvider);
  96.          this.__dropdown.selectMultiple = false;
  97.          this.__dropdown.rowCount = this.__rowCount;
  98.          this.__dropdown.selectedIndex = this.selectedIndex;
  99.          this.__dropdown.vScrollPolicy = "auto";
  100.          this.__dropdown.labelField = this.__labelField;
  101.          this.__dropdown.labelFunction = this.__labelFunction;
  102.          this.__dropdown.owner = this;
  103.          this.__dropdown.changeHandler = this._changeHandler;
  104.          this.__dropdown.scrollHandler = this._scrollHandler;
  105.          this.__dropdown.itemRollOverHandler = this._itemRollOverHandler;
  106.          this.__dropdown.itemRollOutHandler = this._itemRollOutHandler;
  107.          this.__dropdown.resizeHandler = this._resizeHandler;
  108.          this.__dropdown.mouseDownOutsideHandler = function(eventObj)
  109.          {
  110.             var _loc3_ = this.owner;
  111.             var _loc4_ = new Object();
  112.             _loc4_.x = _loc3_._root._xmouse;
  113.             _loc4_.y = _loc3_._root._ymouse;
  114.             _loc3_._root.localToGlobal(_loc4_);
  115.             if(!_loc3_.hitTest(_loc4_.x,_loc4_.y,false))
  116.             {
  117.                if(!(!this.wrapDownArrowButton && this.owner.downArrow_mc.hitTest(_root._xmouse,_root._ymouse,false)))
  118.                {
  119.                   _loc3_.displayDropdown(false);
  120.                }
  121.             }
  122.          };
  123.          this.__dropdown.onTweenUpdate = function(v)
  124.          {
  125.             this._y = v;
  126.          };
  127.          this.__dropdown.setSize(this.__dropdownWidth,this.__dropdown.height);
  128.          this.createObject("BoundingBox","mask",20);
  129.          this.mask._y = this.border_mc.height;
  130.          this.mask._width = this.__dropdownWidth;
  131.          this.mask._height = this.__dropdown.height;
  132.          this.mask._visible = false;
  133.          this.__dropdown.setMask(this.mask);
  134.       }
  135.       return this.__dropdown;
  136.    }
  137.    function setSize(w, h, noEvent)
  138.    {
  139.       super.setSize(w,h,noEvent);
  140.       this.__dropdownWidth = w;
  141.       this.__dropdown.rowHeight = h;
  142.       this.__dropdown.setSize(this.__dropdownWidth,this.__dropdown.height);
  143.    }
  144.    function setEditable(e)
  145.    {
  146.       super.setEditable(e);
  147.       if(e)
  148.       {
  149.          this.text_mc.setText("");
  150.       }
  151.       else
  152.       {
  153.          this.text_mc.setText(this.selectedLabel);
  154.       }
  155.    }
  156.    function get labels()
  157.    {
  158.       return this.__labels;
  159.    }
  160.    function set labels(lbls)
  161.    {
  162.       this.__labels = lbls;
  163.       this.setDataProvider(lbls);
  164.    }
  165.    function getLabelField()
  166.    {
  167.       return this.__labelField;
  168.    }
  169.    function get labelField()
  170.    {
  171.       return this.getLabelField();
  172.    }
  173.    function setLabelField(s)
  174.    {
  175.       this.__dropdown.labelField = this.__labelField = s;
  176.       this.text_mc.setText(this.selectedLabel);
  177.    }
  178.    function set labelField(s)
  179.    {
  180.       this.setLabelField(s);
  181.    }
  182.    function getLabelFunction()
  183.    {
  184.       return this.__labelFunction;
  185.    }
  186.    function get labelFunction()
  187.    {
  188.       return this.getLabelFunction();
  189.    }
  190.    function set labelFunction(f)
  191.    {
  192.       this.__dropdown.labelFunction = this.__labelFunction = f;
  193.       this.text_mc.setText(this.selectedLabel);
  194.    }
  195.    function setSelectedItem(v)
  196.    {
  197.       super.setSelectedItem(v);
  198.       this.__dropdown.selectedItem = v;
  199.       this.text_mc.setText(this.selectedLabel);
  200.    }
  201.    function setSelectedIndex(v)
  202.    {
  203.       super.setSelectedIndex(v);
  204.       this.__dropdown.selectedIndex = v;
  205.       if(v != undefined)
  206.       {
  207.          this.text_mc.setText(this.selectedLabel);
  208.       }
  209.       this.dispatchValueChangedEvent(this.getValue());
  210.    }
  211.    function setRowCount(count)
  212.    {
  213.       if(isNaN(count))
  214.       {
  215.          return undefined;
  216.       }
  217.       this.__rowCount = count;
  218.       this.__dropdown.setRowCount(count);
  219.    }
  220.    function get rowCount()
  221.    {
  222.       return Math.max(1,Math.min(this.length,this.__rowCount));
  223.    }
  224.    function set rowCount(v)
  225.    {
  226.       this.setRowCount(v);
  227.    }
  228.    function setDropdownWidth(w)
  229.    {
  230.       this.__dropdownWidth = w;
  231.       this.__dropdown.setSize(w,this.__dropdown.height);
  232.    }
  233.    function get dropdownWidth()
  234.    {
  235.       return this.__dropdownWidth;
  236.    }
  237.    function set dropdownWidth(v)
  238.    {
  239.       this.setDropdownWidth(v);
  240.    }
  241.    function get dropdown()
  242.    {
  243.       return this.getDropdown();
  244.    }
  245.    function setDataProvider(dp)
  246.    {
  247.       super.setDataProvider(dp);
  248.       this.__dropdown.setDataProvider(dp);
  249.       if(!this._editable)
  250.       {
  251.          this.selectedIndex = 0;
  252.       }
  253.    }
  254.    function open()
  255.    {
  256.       this.displayDropdown(true);
  257.    }
  258.    function close()
  259.    {
  260.       this.displayDropdown(false);
  261.    }
  262.    function get selectedLabel()
  263.    {
  264.       var _loc2_ = this.selectedItem;
  265.       if(_loc2_ == undefined)
  266.       {
  267.          return "";
  268.       }
  269.       if(this.labelFunction != undefined)
  270.       {
  271.          return this.labelFunction(_loc2_);
  272.       }
  273.       if(typeof _loc2_ != "object")
  274.       {
  275.          return _loc2_;
  276.       }
  277.       if(_loc2_[this.labelField] != undefined)
  278.       {
  279.          return _loc2_[this.labelField];
  280.       }
  281.       if(_loc2_.label != undefined)
  282.       {
  283.          return _loc2_.label;
  284.       }
  285.       var _loc3_ = " ";
  286.       for(var _loc4_ in _loc2_)
  287.       {
  288.          if(_loc4_ != "__ID__")
  289.          {
  290.             _loc3_ = _loc2_[_loc4_] + ", " + _loc3_;
  291.          }
  292.       }
  293.       _loc3_ = _loc3_.substring(0,_loc3_.length - 3);
  294.       return _loc3_;
  295.    }
  296.    function hasDropdown()
  297.    {
  298.       return this.__dropdown != undefined && this.__dropdown.valueOf() != undefined;
  299.    }
  300.    function tweenEndShow(value)
  301.    {
  302.       this._y = value;
  303.       this.isPressed = true;
  304.       this.owner.dispatchEvent({type:"open",target:this.owner});
  305.    }
  306.    function tweenEndHide(value)
  307.    {
  308.       this._y = value;
  309.       this.visible = false;
  310.       this.owner.dispatchEvent({type:"close",target:this.owner});
  311.    }
  312.    function displayDropdown(show)
  313.    {
  314.       if(show == this._showingDropdown)
  315.       {
  316.          return undefined;
  317.       }
  318.       var _loc3_ = new Object();
  319.       _loc3_.x = 0;
  320.       _loc3_.y = this.height;
  321.       this.localToGlobal(_loc3_);
  322.       if(show)
  323.       {
  324.          this.__selectedIndexOnDropdown = this.selectedIndex;
  325.          this.__initialSelectedIndexOnDropdown = this.selectedIndex;
  326.          this.getDropdown();
  327.          var _loc2_ = this.__dropdown;
  328.          _loc2_.isPressed = true;
  329.          _loc2_.rowCount = this.rowCount;
  330.          _loc2_.visible = show;
  331.          _loc2_._parent.globalToLocal(_loc3_);
  332.          _loc2_.onTweenEnd = this.tweenEndShow;
  333.          var _loc5_ = undefined;
  334.          var _loc8_ = undefined;
  335.          if(_loc3_.y + _loc2_.height > Stage.height)
  336.          {
  337.             _loc5_ = _loc3_.y - this.height;
  338.             _loc8_ = _loc5_ - _loc2_.height;
  339.             this.mask._y = - _loc2_.height;
  340.          }
  341.          else
  342.          {
  343.             _loc5_ = _loc3_.y - _loc2_.height;
  344.             _loc8_ = _loc3_.y;
  345.             this.mask._y = this.border_mc.height;
  346.          }
  347.          var _loc6_ = _loc2_.selectedIndex;
  348.          if(_loc6_ == undefined)
  349.          {
  350.             _loc6_ = 0;
  351.          }
  352.          var _loc4_ = _loc2_.vPosition;
  353.          _loc4_ = _loc6_ - 1;
  354.          _loc4_ = Math.min(Math.max(_loc4_,0),_loc2_.length - _loc2_.rowCount);
  355.          _loc2_.vPosition = _loc4_;
  356.          _loc2_.move(_loc3_.x,_loc5_);
  357.          _loc2_.tween = new mx.effects.Tween(this.__dropdown,_loc5_,_loc8_,this.getStyle("openDuration"));
  358.       }
  359.       else
  360.       {
  361.          this.__dropdown._parent.globalToLocal(_loc3_);
  362.          delete this.__dropdown.dragScrolling;
  363.          this.__dropdown.onTweenEnd = this.tweenEndHide;
  364.          this.__dropdown.tween = new mx.effects.Tween(this.__dropdown,this.__dropdown._y,_loc3_.y - this.__dropdown.height,this.getStyle("openDuration"));
  365.          if(this.__initialSelectedIndexOnDropdown != this.selectedIndex)
  366.          {
  367.             this.dispatchChangeEvent(undefined,this.__initialSelectedIndexOnDropdown,this.selectedIndex);
  368.          }
  369.       }
  370.       var _loc9_ = this.getStyle("openEasing");
  371.       if(_loc9_ != undefined)
  372.       {
  373.          this.__dropdown.tween.easingEquation = _loc9_;
  374.       }
  375.       this._showingDropdown = show;
  376.    }
  377.    function onDownArrow()
  378.    {
  379.       this._parent.displayDropdown(!this._parent._showingDropdown);
  380.    }
  381.    function keyDown(e)
  382.    {
  383.       if(e.ctrlKey && e.code == 40)
  384.       {
  385.          this.displayDropdown(true);
  386.       }
  387.       else if(e.ctrlKey && e.code == 38)
  388.       {
  389.          this.displayDropdown(false);
  390.          this.dispatchChangeEvent(undefined,this.__selectedIndexOnDropdown,this.selectedIndex);
  391.       }
  392.       else if(e.code == 27)
  393.       {
  394.          this.displayDropdown(false);
  395.       }
  396.       else if(e.code == 13)
  397.       {
  398.          if(this._showingDropdown)
  399.          {
  400.             this.selectedIndex = this.__dropdown.selectedIndex;
  401.             this.displayDropdown(false);
  402.          }
  403.       }
  404.       else if(!this._editable || e.code == 38 || e.code == 40 || e.code == 33 || e.code == 34)
  405.       {
  406.          this.selectedIndex = 0 + this.selectedIndex;
  407.          this.bInKeyDown = true;
  408.          var _loc3_ = this.dropdown;
  409.          _loc3_.keyDown(e);
  410.          this.bInKeyDown = false;
  411.          this.selectedIndex = this.__dropdown.selectedIndex;
  412.       }
  413.    }
  414.    function invalidateStyle(styleProp)
  415.    {
  416.       this.__dropdown.invalidateStyle(styleProp);
  417.       super.invalidateStyle(styleProp);
  418.    }
  419.    function changeTextStyleInChildren(styleProp)
  420.    {
  421.       if(this.dropdown.stylecache != undefined)
  422.       {
  423.          delete this.dropdown.stylecache[styleProp];
  424.          delete this.dropdown.stylecache.tf;
  425.       }
  426.       this.__dropdown.changeTextStyleInChildren(styleProp);
  427.       super.changeTextStyleInChildren(styleProp);
  428.    }
  429.    function changeColorStyleInChildren(sheetName, styleProp, newValue)
  430.    {
  431.       if(this.dropdown.stylecache != undefined)
  432.       {
  433.          delete this.dropdown.stylecache[styleProp];
  434.          delete this.dropdown.stylecache.tf;
  435.       }
  436.       this.__dropdown.changeColorStyleInChildren(sheetName,styleProp,newValue);
  437.       super.changeColorStyleInChildren(sheetName,styleProp,newValue);
  438.    }
  439.    function notifyStyleChangeInChildren(sheetName, styleProp, newValue)
  440.    {
  441.       if(this.dropdown.stylecache != undefined)
  442.       {
  443.          delete this.dropdown.stylecache[styleProp];
  444.          delete this.dropdown.stylecache.tf;
  445.       }
  446.       this.__dropdown.notifyStyleChangeInChildren(sheetName,styleProp,newValue);
  447.       super.notifyStyleChangeInChildren(sheetName,styleProp,newValue);
  448.    }
  449.    function onUnload()
  450.    {
  451.       this.__dropdown.removeMovieClip();
  452.    }
  453.    function _resizeHandler()
  454.    {
  455.       var _loc2_ = this.owner;
  456.       _loc2_.mask._width = this.width;
  457.       _loc2_.mask._height = this.height;
  458.    }
  459.    function _changeHandler(obj)
  460.    {
  461.       var _loc2_ = this.owner;
  462.       var _loc3_ = _loc2_.selectedIndex;
  463.       obj.target = _loc2_;
  464.       if(this == this.owner.text_mc)
  465.       {
  466.          _loc2_.selectedIndex = undefined;
  467.          _loc2_.dispatchChangeEvent(obj,-1,-2);
  468.       }
  469.       else
  470.       {
  471.          _loc2_.selectedIndex = this.selectedIndex;
  472.          if(!_loc2_._showingDropdown)
  473.          {
  474.             _loc2_.dispatchChangeEvent(obj,_loc3_,_loc2_.selectedIndex);
  475.          }
  476.          else if(!_loc2_.bInKeyDown)
  477.          {
  478.             _loc2_.displayDropdown(false);
  479.          }
  480.       }
  481.    }
  482.    function _scrollHandler(obj)
  483.    {
  484.       var _loc2_ = this.owner;
  485.       obj.target = _loc2_;
  486.       _loc2_.dispatchEvent(obj);
  487.    }
  488.    function _itemRollOverHandler(obj)
  489.    {
  490.       var _loc2_ = this.owner;
  491.       obj.target = _loc2_;
  492.       _loc2_.dispatchEvent(obj);
  493.    }
  494.    function _itemRollOutHandler(obj)
  495.    {
  496.       var _loc2_ = this.owner;
  497.       obj.target = _loc2_;
  498.       _loc2_.dispatchEvent(obj);
  499.    }
  500.    function modelChanged(eventObj)
  501.    {
  502.       super.modelChanged(eventObj);
  503.       if(0 == this.__dataProvider.length)
  504.       {
  505.          this.text_mc.setText("");
  506.          delete this.selected;
  507.       }
  508.       else if(this.__dataProvider.length == eventObj.lastItem - eventObj.firstItem + 1 && eventObj.eventName == "addItems")
  509.       {
  510.          this.selectedIndex = 0;
  511.       }
  512.    }
  513.    function dispatchChangeEvent(obj, prevValue, newValue)
  514.    {
  515.       var _loc2_ = undefined;
  516.       if(prevValue != newValue)
  517.       {
  518.          if(obj != undefined && obj.type == "change")
  519.          {
  520.             _loc2_ = obj;
  521.          }
  522.          else
  523.          {
  524.             _loc2_ = {type:"change"};
  525.          }
  526.          this.dispatchEvent(_loc2_);
  527.       }
  528.    }
  529. }
  530.